/*

Animax

Version: 0.1

Proudly developed by Chang Lan, changlan9@gmail.com

*/

#include <cstdlib>
#include <cstdio>
#include <iostream>
#include <stack>
#include <string>
#include "highgui.h"
#include "CImage.h"

using namespace std;

int main(int argc, char** argv)
{
    if(argc == 4)
    {
        cout<<"Preparing to convert the image...\n";
        CPix Pic(argv[2]);
        switch(argv[1][0])
        {
            case 'h':
                Pic.ASC(argv[3],HIGH);
                break;
            case 'l':
                Pic.ASC(argv[3],LOW);
                break;
        }
        return 0;
    }

    if(argc == 3)
    {
        cout<<"Preparing to convert the video. Output text file is iutput.txt by default.\n";
        remove("output.txt");
        CvCapture* Video = cvCaptureFromFile(argv[2]);
        int cntTxt = 0;
        std::ios::sync_with_stdio(false);
        while(1)
        {
            IplImage* frame = cvQueryFrame(Video);
            if(!frame)
                break;
            CPix Pic(frame);
            char szNumber[10];
            sprintf(szNumber,"%d",cntTxt++);
            //Pic.ASC(strcat(szNumber,".txt"));
            switch(argv[1][0])
            {
                case 'h':
                    Pic.ASC("output.txt",HIGH);
                    break;
                case 'l':
                    Pic.ASC("output.txt",LOW);
                    break;
            }
            cout<<"Processing No."<<cntTxt<<endl;
        }

        cvReleaseCapture(&Video);

        return 0;
    }

    cout<<"Usage: \n"
    <<argv[0]<<" [h/l] [input_img] [output_txt]\n"
    <<argv[0]<<" [h/l] [input_video]"<<endl;
    return -1;

}
